package com.kantboot.functional.pay.wechat.controller;

import com.kantboot.functional.pay.wechat.service.IPayWechatService;
import com.kantboot.functional.pay.wechat.util.WechatPayResult;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pay-wechat/wechat")
public class PayWechatController {

    @Resource
    private IPayWechatService service;

    /**
     * 获取支付返回值
     * 小程序支付
     */
    @RequestMapping("/getPayResult")
    public RestResult<WechatPayResult> getPayResult(@RequestParam("orderId") Long orderId, @RequestParam("code") String code) {
        return RestResult.success(service.getPayResult(orderId, code), "getSuccess", "获取成功");
    }

    /**
     * 处理微信支付回调
     * @param order 路径参数
     */
    @RequestMapping("/handleWechatPayCallback/{order}")
    public RestResult handleWechatPayCallback(@PathVariable("order") String order) {
        return RestResult.success(service.handleWechatPay(order), "handleSuccess", "处理成功");
    }

    /**
     * 由前端调用处理微信支付
     */
    @RequestMapping("/handleWechatPay")
    public RestResult handleWechatPay(@RequestParam("orderId") Long orderId) {
        return RestResult.success(service.handleWechatPay(orderId+""), "handleSuccess", "处理成功");
    }

}
